package com.example.weli.ble2test;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.List;

public class UserListAdapter extends ArrayAdapter<User> {
    private int resourceId;

    public UserListAdapter(Context context, int textViewResourceId, List<User> objects) {
        super(context, textViewResourceId, objects);
        this.resourceId = textViewResourceId;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        User user = (User) getItem(position);
        LinearLayout userListItem = new LinearLayout(getContext());
        ((LayoutInflater) getContext().getSystemService("layout_inflater")).inflate(this.resourceId, userListItem, true);
        TextView tvAskedNum = (TextView) userListItem.findViewById(R.id.tv_user_list_name);
        TextView tvLastMsg = (TextView) userListItem.findViewById(R.id.tv_user_list_value);
        ((TextView) userListItem.findViewById(R.id.tv_user_list_Kname)).setText(user.getKname());
        tvAskedNum.setText(user.getname());
        tvLastMsg.setText(user.getvalue());
        return userListItem;
    }
}
